home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / File / Trash Foreign Aliases < prev    next >
Encoding:
Text File  |  1999-03-04  |  3.5 KB  |  174 lines  |  [TEXT/ToyS]

  1. -- Preferences
  2. property kasPrefName : "Foreign Aliases 1.0"
  3.  
  4. -- Globals
  5. global gasInfoWind -- Info window
  6. global gasInfoPos -- Position of info window
  7. global gasFoldersToDo -- The folders left to process
  8. global gasTrashed -- Number gone!
  9. global gasChecked -- Number checked!
  10.  
  11.  
  12. on open fsObjs
  13.     -- Load prefs, show window
  14.     pfLoad()
  15.     
  16.     set gasTrashed to 0
  17.     set gasChecked to 0
  18.     
  19.     set gasInfoWind to display info titled kasPrefName ¬
  20.         located at gasInfoPos ¬
  21.         message "Scanning…"
  22.     
  23.     -- Do files
  24.     set gasFoldersToDo to {}
  25.     
  26.     repeat with fsObj in fsObjs
  27.         set myInfo to (basic info for fsObj)
  28.         
  29.         if (system type of myInfo is "fold") then
  30.             set gasFoldersToDo to gasFoldersToDo & {fsObj}
  31.         else if (catalog kind of myInfo is an alias) then
  32.             DoOne(fsObj)
  33.         end if
  34.     end repeat
  35.     
  36.     -- Do folders
  37.     repeat while gasFoldersToDo is not {}
  38.         -- Pop one off the end
  39.         set n to the number of items of gasFoldersToDo
  40.         set fsObj to item n of gasFoldersToDo
  41.         
  42.         if (n > 1) then
  43.             set gasFoldersToDo to items 1 through (n - 1) of gasFoldersToDo
  44.         else
  45.             set gasFoldersToDo to {}
  46.         end if
  47.         
  48.         display info gasInfoWind ¬
  49.             message ("Folders to go: " & n) ¬
  50.             at line 6 ¬
  51.             using color (15 * 32)
  52.         
  53.         -- Process it
  54.         GoDeep(fsObj)
  55.     end repeat
  56.     
  57.     display info gasInfoWind message "DONE!"
  58.     
  59.     pause for 5 with seconds timing -- Let screen wait...
  60.     
  61.     set gasInfoPos to screen location of ¬
  62.         (display info gasInfoWind with disposal)
  63.     
  64.     pfSave() -- Save window location
  65. end open
  66.  
  67.  
  68. on DoOne(fsObj)
  69.     set aFileInfo to (alias info from fsObj)
  70.     
  71.     display info gasInfoWind ¬
  72.         message "File: " & (original name of aFileInfo) ¬
  73.         at line 2
  74.     
  75.     set gasChecked to gasChecked + 1
  76.     
  77.     try
  78.         set myAlias to («event ÅkuFFiLA» fsObj)
  79.     on error
  80.         TrashFile(fsObj, "Alias load error.")
  81.         return
  82.     end try
  83.     
  84.     set aInfo to alias info from myAlias
  85.     
  86.     if (alias server of aInfo is not "") then
  87.         TrashFile(fsObj, "Server alias.")
  88.         return
  89.     end if
  90.     
  91.     if (ARA number of aInfo is "") then
  92.         try
  93.             set myInfo to extended info for myAlias
  94.         on error
  95.             TrashFile(fsObj, "Alias resolve error.")
  96.             return
  97.         end try
  98.         
  99.         display info gasInfoWind message ¬
  100.             (vol name of myInfo) & " <-> " & (alias volume of aFileInfo) ¬
  101.             at line 13
  102.         
  103.         if (vol name of myInfo) is not (alias volume of aFileInfo) then ¬
  104.             TrashFile(fsObj, "Foreign volume.")
  105.     else
  106.         TrashFile(fsObj, "Remote Access alias.")
  107.     end if
  108.     
  109.     display info gasInfoWind ¬
  110.         message ("Checked: " & gasChecked) ¬
  111.         at line 7 ¬
  112.         using color 15
  113. end DoOne
  114.  
  115.  
  116. on TrashFile(fsObj, reason)
  117.     display info gasInfoWind ¬
  118.         message reason at line 3
  119.     
  120.     collate fsObj with the trasher
  121.     
  122.     set gasTrashed to gasTrashed + 1
  123.     
  124.     display info gasInfoWind ¬
  125.         message ("Trashed: " & gasTrashed) ¬
  126.         at line 8 ¬
  127.         using color (15 * 1024)
  128. end TrashFile
  129.  
  130.  
  131. on GoDeep(foldObj)
  132.     display info gasInfoWind ¬
  133.         message "Path: " & (foldObj as string)
  134.     
  135.     set daddy to foldObj as string
  136.     
  137.     -- Do aliases
  138.     display info gasInfoWind ¬
  139.         message "Scanning aliases" at line 5
  140.     
  141.     set myItems to the entries in foldObj ¬
  142.         whose kinds are an alias
  143.     
  144.     repeat with myItem in myItems
  145.         DoOne((daddy & myItem) as alias)
  146.     end repeat
  147.     
  148.     -- Do folders
  149.     display info gasInfoWind ¬
  150.         message "Scanning subfolders" at line 5
  151.     
  152.     set myItems to the entries in foldObj ¬
  153.         whose kinds are a folder
  154.     
  155.     repeat with myItem in myItems
  156.         set gasFoldersToDo to gasFoldersToDo & {(daddy & myItem) as alias}
  157.     end repeat
  158. end GoDeep
  159.  
  160.  
  161. on pfLoad()
  162.     try
  163.         set ourPrefs to (load preference named kasPrefName)
  164.         set gasInfoPos to item 1 of ourPrefs
  165.     on error
  166.         set gasInfoPos to {0, 0}
  167.     end try
  168. end pfLoad
  169.  
  170.  
  171. on pfSave()
  172.     save preference {gasInfoPos} named kasPrefName
  173. end pfSave
  174.